How to connect to the LANDesk MBSDK using C#?
This article is to demonstrate to LANDesk admins how to connect to the LANDesk MBSDK with C#.
Prerequisites
LANDesk
- A LANDesk Core Server accessible via the network.
- Credentials to connect to the LANDesk Core Server.
Basically if you can hit the MBSDK with a browser and login, you are good to go.
http://CoreServer/mbsdkservice/msgsdk.asmx
Visual Studio
- It is assumed that you have Visual Studio Professional installed
Step 1 – Create a Visual Studio Project
- In Visual Studio, Go to File | New | Project.
- Select that project type.
Note: For this example I chose Console Application. - Give the Project a name.
Note: I named my project TalkToMBSDK. - Click OK.
Note: I went ahead and left my client application configured for .NET 4 even though I know the server currently is .NET 3.5 Sp1.
Step 2 – Add a Web Reference to the MBSDK
- In you new Visual Studio project, right-click on the project and click Add Service Reference.
Note: We actually need a Web Reference but this is how we get there. - Click Advanced on the bottom left.
- Click on Add Web Reference, also on the bottom left.
- Enter the URL to the MBSDK on your Core Server: http://CoreServer/mbsdkservice/msgsdk.asmx
- Change the Web Reference Name (on the right) to mbsdk.
Note: You can name it whatever you want, but because there is an object called MBSDK (all uppercase), I chose to make the namespace mbsdk (all lowercase). - Click Add Reference.
Step 3 – Test using the LANDesk SDK
- In the Program.cs add the following code. You next steps are in the code comments.
using System.Net; using TalkToMBSDK.mbsdk; namespace TalkToMBSDK { class Program { static void Main(string[] args) { // Step 1 - You need to use your credentials string user = "SomeUser"; string password = "SomePassword"; string domain = "SomeDomain.tld"; // Step 2 - Configure a CredentialCache object with the URL and your creds string uri = "http://CoreServer/MBSDKService/MsgSDK.asmx"; CredentialCache MyCredentialCache = new System.Net.CredentialCache(); MyCredentialCache.Add(new System.Uri(uri), "NTLM", new NetworkCredential(user, password, domain)); // Step 3 - Create an MBSDK object and set its CredentialCache object to the one you just created MBSDK sdk = new MBSDK(); sdk.Credentials = MyCredentialCache; // Step 4 - Go ahead an call methods from the MBSDK // Note: If you get 401 unathorized, are you a LANDesk Administrator? string[] configs = sdk.GetClientConfigurations(); DeviceList list = sdk.ListMachines(""); string who = sdk.WhoAmI(); } } }
Have fun LANDesk Admins.